#ifndef __SOCKETSENDBUFF_HEADER
#define __SOCKETSENDBUFF_HEADER

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct SocketSendBuff {
	const char *buff;
	int status;
	ssize_t index;
	int length;
	int remain;

	SocketSendBuff(const char *str, const ssize_t size):
		buff(str), length(size) {
			status = 0;
			index = 0;
			remain = size;
		}
	~SocketSendBuff() {}

	ssize_t write_data(int fd) {
		while (true) {
			ssize_t n = write(fd, buff+index, remain);
			if (n == -1 || n == 0) return n;
			index += n;
			remain -= n;
			if (remain == 0) {
				status = 1;
				break;
			}
		}
		return length;
	}

	bool finish() {
		return status >= 1;
	}

};

#endif // __SOCKETSENDBUFF_HEADER
